#-*- encoding: utf-8 -*-
import win32com.client 
from Misc.Utils import *

from DataAccess.QueryBlp import *

from datetime import date,timedelta

from ReportTool.HldReport import *
from ReportTool.PnLReport import *
from ReportTool.NAVReport import *
from ReportTool.MktValReport import *
from ReportTool.TradeReport import *
from ReportTool.RealizedPnL import *
from ReportTool.OnshoreHldReport import *

from Config.ReportConfig import *
	
def Annual_PnL(ref_date, portf_list):

	start_date = date(ref_date.year, 1, 1)
	pnl = query_pnl(start_date, ref_date, portf_list)
	
	tplt_file = TPLT_PATH + 'Annual PnL.xls'
	xApp = win32com.client.Dispatch("Excel.Application")
	xBook = xApp.Workbooks.Open(tplt_file)
	xSht = xBook.Worksheets('Report')
	
	row = 2
	for elem in pnl:
		xSht.Cells(row, 1).Value = elem[0]
		xSht.Cells(row, 2).Value = elem[1]
		xSht.Cells(row, 3).Value = elem[2]
		xSht.Cells(row, 4).Value = elem[3]
		xSht.Cells(row, 5).Value = elem[4]
		xSht.Cells(row, 6).Value = elem[7]
		xSht.Cells(row, 7).Value = elem[5]
		xSht.Cells(row, 8).Value = elem[8]
		xSht.Cells(row, 9).Value = elem[6]
		xSht.Cells(row, 10).Value = elem[10]
		
		row += 1
	
	rept_file = REPT_PATH + 'Annual PnL_''' + str(ref_date.year) + '.xls'
	xBook.SaveAs(rept_file)
	xBook.Close()
	del xApp
	
	print 'info, annual pnl report completed at ', ref_date.isoformat()